import Vue from "vue";
import App from "./App.vue";
import store from "./store";
import funcs from "./utils/funcs";
import others from "./utils/others";
import antd from "./components/antd";
import comps from "./components/index";
import directives from "./directives/index";
import http from "./utils/http";
import storage from "./utils/storage";

Vue.config.productionTip = false;

import "ant-design-vue/dist/antd.css";

let userInfo = storage.get("userInfo"),
  token;
if (userInfo) {
  token = storage.get(userInfo.userName + "_token");
  if (token) {
    // 验证token是否有效
    http("/user/hasLogin", {
      token: token,
      userName: userInfo.userName,
    }).then((res) => {
      if (res.code) {
        store.commit("userInfo", userInfo);
        store.commit("hasLogin", true);
        let links = storage.get(userInfo.userName + "_links");
        store.commit("links", links);
      }
      store.commit("status", true);
    });
  } else {
    store.commit("userInfo", {});
    store.commit("hasLogin", false);
    store.commit("status", true);
  }
} else {
  store.commit("status", true);
}

Vue.prototype.$funcs = funcs;
Vue.prototype.$storage = storage;
Vue.prototype.$http = http;
Vue.use(antd);
Vue.use(directives);
Vue.use(others);
Vue.use(comps);

new Vue({
  store,
  render: (h) => h(App),
}).$mount("#app");
